#!/usr/bin/env python

"""
Copy the most recent batch of hist files in a case, adding the given suffix.
This allows us to save these results if we want to run the case again.
"""

from standard_script_setup import *

from CIME.case       import Case
from CIME.hist_utils import copy_histfiles

###############################################################################
def parse_command_line(args, description):
###############################################################################
    parser = argparse.ArgumentParser(
        usage="""\n{0} suffix [<casedir>] [--verbose]
OR
{0} --help

\033[1mEXAMPLES:\033[0m
    \033[1;32m# Setup case \033[0m
    > {0}
""".format(os.path.basename(args[0])),
        description=description,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    CIME.utils.setup_standard_logging_options(parser)

    parser.add_argument("--suffix",
                        help="Suffix to append to hist files")

    parser.add_argument("caseroot", nargs="?", default=os.getcwd(),
                        help="Case directory")

    args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser)

    return args.suffix, args.caseroot

###############################################################################
def _main_func(description):
###############################################################################
    suffix, caseroot = parse_command_line(sys.argv, description)
    with Case(caseroot) as case:
        copy_histfiles(case, suffix)

if __name__ == "__main__":
    _main_func(__doc__)
